package com.codeplex.springsurv.controllers;

import com.codeplex.springsurv.*;
import com.codeplex.springsurv.businessLogic.SurveyService;
import com.codeplex.springsurv.businessLogic.UserService;
import com.codeplex.springsurv.dataaccess.mappers.*;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;
import org.apache.ibatis.annotations.Param;


@Controller
public class UserController {
	
	private static final Logger logger = LoggerFactory.getLogger(UserController.class);
	
	
	@Resource(name = "UserService")
	private UserService userService;
	
	@Resource(name = "SurveyService")
	private SurveyService surveyService;
	
	@RequestMapping(value = "/users/login", method = RequestMethod.POST)
	//Obtener el usuario (Login de usuario).
	//public ModelAndView getUserByNick(@RequestBody final User pUser) throws IOException {
	public Object login(@RequestBody final User pUser, HttpServletResponse response) {
		
		return JsonView.Render(this.userService.getAuthUser(pUser), response);
		
	}
	
	@RequestMapping(value = "/users", method = RequestMethod.POST)
	public void insertUser(@RequestBody final User pUser) throws IOException {
		
		this.userService.insertNewUser(pUser);
	}
	

}
